package com.itheima.jdbctemplate;

import com.itheima.domain.Account;
import org.omg.CORBA.INTERNAL;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class JdbcTemplateDemo03 {
    public static void main(String[] args) {

            //获取容器
            ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
            //获取对象
            JdbcTemplate jt = ac.getBean("jdbcTemplate", JdbcTemplate.class);



            /*BeanPropertyRowMapper<Account>(Account.class)
            * spring提供的结果集封装类
            * */

            //查询方法
            List<Account> accounts = jt.query("select * from account where money>?",
                    new BeanPropertyRowMapper<Account>(Account.class), 500);
            for (Account account : accounts) {
                System.out.println(account);
            }

            //查询返回的是 一个字段
        Integer i = jt.queryForObject("select count(*) from account where money>?", Integer.class, 500);
        System.out.println(i);

    }

}
